using Microsoft.VisualBasic.ApplicationServices;
using System;
using System.Diagnostics;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using File = System.IO.File;


namespace 快速打开程序
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }



        private void button2_Click(object sender, EventArgs e)
        {
            string appPath = @"C:\Program Files\IIS Express\iisexpress.exe";

            openExeAdmin(appPath);
        }

        public void openExe(string AppPath)
        {
            // 应用程序的路径


            // 检查文件是否存在
            if (File.Exists(AppPath))
            {
                // 使用Process类启动应用程序
                Process.Start(AppPath);
            }
            else
            {
                // 如果文件不存在，则显示错误消息
                MessageBox.Show("文件不存在，请检查路径是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 以管理员权限运行程序
        /// </summary>
        /// <param name="AppPath"></param>
        private void openExeAdmin(string AppPath)
        {
            // 应用程序的路径
            // 检查文件是否存在
            if (File.Exists(AppPath))
            {
                // 使用Process类启动应用程序，并请求管理员权限
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute = true;
                startInfo.WorkingDirectory = Path.GetDirectoryName(AppPath);
                startInfo.FileName = AppPath;
                startInfo.Verb = "runas"; // 请求管理员权限
                try
                {
                    Process.Start(startInfo);
                }
                catch (Exception ex)
                {
                    // 用户取消提升权限或发生错误
                    MessageBox.Show("无法以管理员身份运行应用程序。错误信息: " + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                // 如果文件不存在，则显示错误消息
                MessageBox.Show("文件不存在，请检查路径是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }




        private void Form1_Load(object sender, EventArgs e)
        {
            // 设置按钮的FlatStyle为Flat，这样背景色才能正确显示
            //  button1.FlatStyle = FlatStyle.Flat;

            // 移除按钮的边框
            // button1.FlatAppearance.BorderSize = 0;
            // 设置按钮背景为半透明
            // button1.BackColor = Color.FromArgb(128, button1.BackColor);


            // 如果您想要一个具有特定颜色的半透明按钮，可以这样做
            // button1.BackColor = Color.FromArgb(128, 255, 0, 0); // 半透明的红色背景




            // 设置按钮背景为半透明
            label1.BackColor = Color.FromArgb(128, label1.BackColor);
            label2.BackColor = Color.FromArgb(128, label2.BackColor);


        }
        #region

        /*
        // 指定文件夹的路径
        string folderPath = @"E:\Gitee项目\项目14_快速打开程序\快速打开程序";
        // 检查文件夹是否存在
        if (Directory.Exists(folderPath))
        {
            // 使用cmd执行git命令
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "cmd.exe";
            startInfo.WorkingDirectory = folderPath;
            startInfo.Arguments = "/C git push -f origin master";
            startInfo.UseShellExecute = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.CreateNoWindow = true;
            using (Process process = new Process())
            {
                process.StartInfo = startInfo;
                process.Start();
                // 可以读取命令的输出
                string output = process.StandardOutput.ReadToEnd();
                // 等待命令执行完成
                process.WaitForExit();
                // 可以在这里处理输出或者显示给用户
                MessageBox.Show("强推成功", "git push", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        else
        {
            // 如果文件夹不存在，则显示错误消息
            MessageBox.Show("文件夹不存在，请检查路径是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }





        //打开文件夹
        /*
         // 打开文件夹的路径
        string folderPath = @"D:\Your\Folder\Path";
        // 检查文件夹是否存在
        if (Directory.Exists(folderPath))
        {
            // 使用Explorer打开文件夹
            Process.Start("explorer", folderPath);


         */




        #endregion



        private void btnIO_Click(object sender, EventArgs e)
        {
            string appPath = @"E:\Gitee项目\项目14_快速打开程序\dgvIO\dgvIO.exe";

            openExe(appPath);
        }

        private void halfButton1_Click(object sender, EventArgs e)
        {
            string appPath = @"D:\小工具\ICO图标转换(64位)\ICO图标转换(64位).exe";

            openExe(appPath);
        }

        private void halfButton2_Click(object sender, EventArgs e)
        {
            string appPath = @"D:\小工具\输送线状态生成\dgvDemo1 输送机反馈区.exe";

            openExe(appPath);
        }

        private void halfButton3_Click(object sender, EventArgs e)
        {
            string appPath = @"D:\小工具\录屏\ScreenRecording.exe";

            openExe(appPath);
        }

        private void halfButton4_Click(object sender, EventArgs e)
        {
            string appPath = @"C:\Program Files\IIS Express\iisexpress.exe";

            openExeAdmin(appPath);
        }

        private void halfButton5_Click(object sender, EventArgs e)
        {
            string appPath = @"D:\小工具\截图文本识别\OcrTools.exe";

            openExe(appPath);
        }

        private void halfButton6_Click(object sender, EventArgs e)
        {
            gitForm form = new gitForm();
            form.ShowDialog();
        }

        //生成 PreComand SCL
        private void btnPreCommand_Click(object sender, EventArgs e)
        {
            string appPath = @"E:\Gitee项目\项目14_快速打开程序\dgvPreCommand\WindowsFormsApp1.exe";

            openExe(appPath);
            //E:\Gitee项目\项目14_快速打开程序\dgvPreCommand
        }

        private void btnXOR_Click(object sender, EventArgs e)
        {
            string appPath = @"E:\Gitee项目\项目1_C_Sharp101\C_Sharp101\Class008 DataGridView控件\dgvDemo4 XOR\XOR\bin\Debug\net8.0-windows\dgvDemo4 XOR.exe";
            openExe(appPath);
        }

        /// <summary>
        /// FPT快传
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFTP_Click(object sender, EventArgs e)
        {
            string appPath = @"E:\Gitee项目\项目37_FTP\FTP快传\FTP\bin\Debug\net8.0-windows\FTP.exe";
            openExe(appPath);
        }

        private void btnChangeIP_Click(object sender, EventArgs e)
        {
            string appPath = @"E:\Gitee项目\项目36_快捷更改改网卡IP\ChangIP\ChangIP_NET8.0\ChangeIP\bin\Debug\net8.0-windows\ChangeIP.exe";
            openExe(appPath);
        }
    }
}